import { configureStore } from "@reduxjs/toolkit";
import counter from "./reducers/counter";
import user from "./reducers/user";
import logger from "redux-logger";

import auth from "./reducers/auth";

import clientRequest from "../client/reques";
import serverRequest from "../server/reques";
const reducer = {
  counter, // 或者可以更明确地使用 counter: counter
  user,
  auth
};
export function getClientStore() {
  console.log(window.context,'window.context')
  // const initialState = window.context.store || {};
  console.log(window.context,'window.context')
  const store = configureStore({
    reducer, // 使用合并后的 reducer
    preloadedState: window.context.store || {}, // 设置初始状态
    middleware: (getDefaultMiddleware) =>
      getDefaultMiddleware({ thunk: { extraArgument: clientRequest } }).concat(
        logger
      ), // 默认已经包含了 thunk 和 promise
  });

  return store;
}

export function getServerStore() {
  const store = configureStore({
    reducer,
    middleware: (getDefaultMiddleware) =>
      getDefaultMiddleware({ thunk: { extraArgument: serverRequest } }).concat(
        logger
      ), // 默认已经包含了 thunk 和 promise
  });

  return store;
}
